package com.xiaoyi.intentsdklibrary.Utils;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import java.util.ArrayList;
import java.util.Iterator;

public class ArrayGson<T> {
    public <T> T fromJson(String str, Class<T> cls) {
        try {
            return (T) new Gson().fromJson(str, (Class) cls);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public String toJson(Object obj) {
        return new Gson().toJson(obj);
    }

    public  ArrayList fromJsonList(String str, Class<T> cls) {
        try {
            ArrayList<Object> arrayList = (ArrayList<Object>) new ArrayList();
            Iterator<JsonElement> it = new JsonParser().parse(str).getAsJsonArray().iterator();
            while (it.hasNext()) {
                Object o = new Gson().fromJson(it.next(), (Class) cls);
                arrayList.add(o);
            }
            return arrayList;
        } catch (Exception unused) {
            return null;
        }
    }
}
